﻿using Kingdee.BOS.Core.ListFilter;
using Kingdee.BOS.JSON;
using Kingdee.BOS.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RK.FilterPlugin.BPW
{
    [Description("简单账表过滤插件，添加下拉列表值"), HotUpdate]
    public class PickSumReportFilter : AbstractListFilterPlugIn
    {
        public override void FireBeforeBindFilterMetadata(EventArgs e)
        {
            base.FireBeforeBindFilterMetadata(e);
            if (this.View.ParentFormView != null && this.View.ParentFormView.BillBusinessInfo.GetForm().Id.Equals("POSW_PickSumReport", StringComparison.OrdinalIgnoreCase))
            {
                
                // 当前列表过滤窗体为采购订单列表时，动态填充过滤条件中的下拉列表字段的下拉项
                var cmbField = this.CommonFilterModel.FilterObject.FilterFieldList.FirstOrDefault(t => t.Key.EqualsIgnoreCase("F_POSW_ComboPeriod"));
                if (cmbField == null)
                {
                    return;
                }
                var commonFilterEditor = cmbField.Editor;
                var quickFilterEditor = cmbField.QuickFilterEditor;
                var oldItems = (JSONArray)commonFilterEditor.Get("store");
                // 动态获取下拉项集合
                var newItems = GetItems();
                commonFilterEditor.Put("store", newItems);
                quickFilterEditor.Put("store", newItems);
            }
        }
        /// <summary>
        /// 获取下拉列表的下拉项集合
        /// </summary>
        /// <returns></returns>
        private JSONArray GetItems()
        {
            var items = new JSONArray();
            // 模拟动态生成下拉列表的下拉项
            var item = new JSONArray();
            item.Add("202501");
            item.Add("202501");
            items.Add(item);
            item = new JSONArray();
            item.Add("202502");
            item.Add("202502");
            items.Add(item);
            item = new JSONArray();
            item.Add("202503");
            item.Add("202503");
            items.Add(item);
            item = new JSONArray();
            item.Add("202504");
            item.Add("202504");
            items.Add(item);
            item = new JSONArray();
            item.Add("202505");
            item.Add("202505");
            items.Add(item);
            return items;
        }
    }
}
